package ${packageName}.controller;

import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;

import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.security.LoginUserUtil;
import com.retail.global.annon.TraceLog;
import ${packageName}.service.${entityName}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* ${codeGenComment} API
* @author Administrator
*/
@Api(tags = "${codeGenComment} API")
@RestController
@RequestMapping("/${lowerEntityName}")
public class ${entityName}Controller extends AbstractCommonController${r'<'}${entityName}Service${r','} ${entityName}Request${r','} ${entityName}Vo${r'>'}{

    @Autowired
    private ${entityName}Service ${lowerEntityName}Service;

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(${lowerEntityName}Service, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存${codeGenComment}")
    public ${r'Result<Integer>'} save(@RequestBody ${entityName}Request request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(${lowerEntityName}Service, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新${codeGenComment}")
    public ${r'Result<Integer>'} update(@RequestBody ${entityName}Request request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(${lowerEntityName}Service, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("${codeGenComment}-查询")
    public ${r'Result<List<'}${entityName}Vo${r'>>'}listPage(@RequestBody ParamReq req) {
        return super.listPage(${lowerEntityName}Service, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("${codeGenComment}-统计")
    public ${r'Result<Integer>'} countPage(@RequestBody ParamReq req) {
        return super.countPage(${lowerEntityName}Service, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("${codeGenComment}-分页数据")
    public ${r'Result<PageResult>'} page(@RequestBody ParamReq${r'<'}${entityName}Request${r'>'} req) {
        return super.page(${lowerEntityName}Service, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除${codeGenComment}")
    public ${r'Result<Integer>'} delete(@PathVariable("id") Long id) {
        return super.delete(${lowerEntityName}Service, id);
    }

    @TraceLog()
    @ApiOperation("批量删除${codeGenComment}")
    @DeleteMapping("{ids}")
    public ${r'Result<Integer>'} batchDelete(${r'List<Long>'} ids) {
        return super.batchDelete(${lowerEntityName}Service, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
